<?php
	//show custom fields in custom post type property.
	$zon_area = get_post_meta($post->ID, 'zon_area', true);
	$zon_bedroom = get_post_meta($post->ID, 'zon_bedroom', true);
	$zon_tolet = get_post_meta($post->ID, 'zon_tolet', true);
	$zon_garage = get_post_meta($post->ID, 'zon_garage', true);
	$zon_lease = get_post_meta($post->ID, 'zon_lease', true);
	$zon_price = get_post_meta($post->ID, 'zon_price', true);
	$zon_address = get_post_meta($post->ID, 'zon_address', true);
	$zon_latitude = get_post_meta($post->ID, 'zon_latitude', true);
	$zon_longitude = get_post_meta($post->ID, 'zon_longitude', true);
	$agents = get_post_meta($post->ID, 'agents', true);
?>
<!-- include css -->
<link rel="stylesheet" type="text/css" href="<?php echo INCLUDES_DIR; ?>/posttypes/property/css/style.css" media="screen" />
<!-- include js -->
<script type="text/javascript" src="<?php echo INCLUDES_DIR; ?>/posttypes/property/js/gmap3.min.js"></script>
<script type='text/javascript' src='http://maps.googleapis.com/maps/api/js?sensor=false'></script>
<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery('.bpanel-tabbed-meta .tabs li').click(function() {
			if(jQuery(this).attr('class').indexOf('current') == -1) {
				var clickedIndex = jQuery(this).index();
				jQuery(this).addClass('current').siblings('.current').removeClass('current');
				console.log(clickedIndex);
				jQuery(this).parent().siblings('.tabbed').children('li.current').removeClass('current');
				jQuery(this).parent().siblings('.tabbed').children('li:eq('+clickedIndex+')').addClass('current');
			}
		});
	});
</script>
<script type="text/javascript" charset="utf-8">
	jQuery(document).ready(function() {
		jQuery("#zon_address").blur(loadmap);
		jQuery("#zon-location").on("click",function(event){
			event.preventDefault();
			loadInitMap();
			loadmap();
		});
		function loadmap() {
			var the_address = jQuery("#zon_address").val();
			var geocoder = new google.maps.Geocoder();
			var latLng = geocoder.geocode({
				address: the_address
			}, function(results, status) {
				if(status == google.maps.GeocoderStatus.OK) {
					lat = results[0].geometry.location.lat();
					lng = results[0].geometry.location.lng();										
					jQuery('#zon_latitude').val(lat);
					jQuery('#zon_longitude').val(lng);										
					jQuery(gMap).gmap3({
						get: {
							name: 'marker',
							all: true,
							callback: function(objs) {
								jQuery.each(objs, function(i, obj) {
									obj.setMap(null);
								})
							}
						},
						map: {
							options: {				
								zoom: 10,
								center: new google.maps.LatLng(lat, lng)
							}
						},
						marker: {
							values: [{ latLng:[lat, lng] }],
							options: {
								
								draggable: true
								
							},
							events: {
								mouseup: function(marker, event, context) {
									var thePos = marker.getPosition();
									var theLat = thePos.jb;
									var theLng = thePos.kb;
									jQuery('#zon_latitude').val(theLat);
									jQuery('#zon_longitude').val(theLng);
								}
													
							}
												
						}
											
					});						
				} else {
					
				}					
			});				
		};
	});
	
	function loadInitMap() {
		
		if(typeof gMap == 'undefined') {
			gMap = jQuery('#property-loc');
			gMap.gmap3({
				map: {
					options: {
						zoom: 2,
						mapTypeId: google.maps.MapTypeId.ROADMAP,
						mapTypeControl: true,
						mapTypeControlOptions: {
						  style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
						},
						navigationControl: true,
						scrollwheel: true,
						streetViewControl: false
					}
				}
			});
		}
	};
	function zonthemes_loadmap(){
		loadInitMap();
		loadmap();
	}
</script>
<div class="bpanel-tabbed-meta">
	<ul class="tabs">
		<li class="bpanel-tab current"><?php _e('Amenities','zonthemes'); ?></li>
		<li class="bpanel-tab"><?php _e('Pricing','zonthemes'); ?></li>
		<li class="bpanel-tab" id="zon-location"><?php _e('Localtion','zonthemes'); ?></li>
		<li class="bpanel-tab"><?php _e('Agent','zonthemes'); ?></li>
	</ul>
	<div class="clear"></div>
	
	<ul class="tabbed">
		<li class="current">
			<div class="zon-line">
				<div class="zon-lable"><?php _e('Area','zonthemes'); ?></div>
				<div class="zon-input">
					<input type="text" name="zon_area" id="zon_area" value="<?php echo $zon_area; ?>" />
				</div>
				<div class="zon-desc">
					<p><?php _e('Insert Area','zonthemes'); ?></p>
				</div>
			</div><!--end .zon-line-->
			<div class="zon-line">
				<div class="zon-lable"><?php _e('Bedrooms','zonthemes'); ?></div>
				<div class="zon-input">
					<input type="text" name="zon_bedroom" id="zon_bedroom" value="<?php echo $zon_bedroom; ?>" />
				</div>
				<div class="zon-desc">
					<p><?php _e('Number of bedrooms - Leave empty to not show.','zonthemes'); ?></p>
				</div>
			</div><!--end .zon-line-->
			<div class="zon-line">
				<div class="zon-lable"><?php _e('Tolets','zonthemes'); ?></div>
				<div class="zon-input">
					<input type="text" name="zon_tolet" id="zon_tolet" value="<?php echo $zon_tolet; ?>" />
				</div>
				<div class="zon-desc">
					<p><?php _e('Number of tolets - Leave empty to not show.','zonthemes'); ?></p>
				</div>
			</div><!--end .zon-line-->
			<div class="zon-line">
				<div class="zon-lable"><?php _e('Car spaces','zonthemes'); ?></div>
				<div class="zon-input">
					<input type="text" name="zon_garage" id="zon_garage" value="<?php echo $zon_garage; ?>" />
				</div>
				<div class="zon-desc">
					<p><?php _e('Number of Car Spaces - Leave empty to not show.','zonthemes'); ?></p>
				</div>
			</div><!--end .zon-line-->
		</li>
		<li>
			<div class="zon-line">
				<div class="zon-lable"><?php _e('Sale or Rental','zonthemes'); ?></div>
				<div class="zon-input">
					<select name="zon_lease" id="zon_lease">
						<option value="sale"<?php if($zon_lease == 'sale') { echo ' selected="selected"'; } ?>><?php _e('Sale','zonthemes'); ?></option>
						<option value="rental"<?php if($zon_lease == 'rental') { echo ' selected="selected"'; } ?>><?php _e('Rental','zonthemes'); ?></option>
					</select>
				</div>
				<div class="zon-desc">
					<p><?php _e('Is the property for sale or rental?','zonthemes'); ?></p>
				</div>
			</div><!--end .zon-line-->
			<div class="zon-line">
				<div class="zon-lable"><?php _e('Price','ZONREAL'); ?></div>
				<div class="zon-input">
					<input type="text" name="zon_price" id="zon_price" value="<?php echo $zon_price; ?>" />
				</div>
				<div class="zon-desc">
					<p><?php _e('Price - Full price for sales, per week for rentals.</br>example: 900,000 - input 900000</br>example: 900,000.05 - input 900000.05','zonthemes'); ?></p>
				</div>
			</div><!--end .zon-line-->
		</li>
		<li>
			<div class="zon-line">
				<div class="zon-lable"><?php _e('Address','zonthemes'); ?></div>
				<div class="zon-input">
					<input type="text" value="<?php echo $zon_address; ?>" id="zon_address" name="zon_address" />
				</div>
				<div class="zon-desc">
					<p><?php _e('Property Address. Google uses this address to set your pin. If Google is not able to find the location using this address please use latitude and longitude.','zonthemes'); ?></p>
					<p><?php _e('Once you enter your address you will get the latitude and longitude autmatically. These can be set individually as well.','zonthemes'); ?></p>
				</div>
				<input type="hidden" value="<?php echo $zon_latitude; ?>" id="zon_latitude" name="zon_latitude" />
				<input type="hidden" value="<?php echo $zon_longitude; ?>" id="zon_longitude" name="zon_longitude" />
			</div><!--end .zon-line-->
			<div style="width: 100%; height: 300px;" id="property-loc"></div>
		</li>
		<li>
			<div class="zon-line">
				<div class="zon-lable"><?php _e('Select property Agent','zonthemes'); ?></div>
				<div class="zon-input">
					<select name="agents[]" id="agents" multiple="multiple">
						<?php $q = new WP_Query(array('post_type'=>'agents', 'showposts'=>-1)); ?>
						<?php if($q->have_posts()) : while($q->have_posts()) : $q->the_post(); ?>
							<option value="<?php echo get_the_ID(); ?>"<?php if(is_array($agents)) { if(in_array(get_the_ID(), $agents)) { echo ' selected="selected"'; } } ?>><?php the_title(); ?></option>
						<?php endwhile; wp_reset_query(); endif; ?>
					</select>
				</div>
				<div class="zon-desc">
					<p><?php _e('Property Agents. Enquiries will be sent to the admin as well as these agents. They are displayed on their respective pages by default (this can be disabled in the custom admin panel). Press Cmd/Ctrl + click to select multiple.','zonthemes'); ?></p>
				</div>
			</div><!--end .zon-line-->
		</li>
	</ul>
</div>